package com.xuelang.pipeline.client.application;

import com.xuelang.pipeline.client.application.dto.ApplicationComponentDTO;
import com.xuelang.pipeline.client.application.dto.ApplicationDTO;
import com.xuelang.pipeline.client.application.dto.ApplicationQuery;
import com.xuelang.pipeline.client.application.dto.MyApplicationDTO;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import java.util.List;

/**
 * 应用服务API
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
public interface IApplicationService {

    /**
     * 查询应用列表(有过滤条件，可以分页)
     *
     * @param dtoPageParam
     * @return
     */
    @PostMapping(value = "/pageList", produces = "application/json;charset=utf-8")
    ApiResult<PageRecord<ApplicationDTO>> pageApplicationList(@RequestBody @Valid PageParam<ApplicationQuery> dtoPageParam);

    /**
     * 查询我的应用列表(有过滤条件，可以分页)
     *
     * @param dtoPageParam
     * @return
     */
    @PostMapping(value = "/myApps", produces = "application/json;charset=utf-8")
    ApiResult<PageRecord<MyApplicationDTO>> pageMyApplications(@RequestBody @Valid PageParam<ApplicationQuery> dtoPageParam);

    /**
     * 查询应用列表-携带组件信息(无过滤条件)
     *
     * @param applicationQuery
     * @return
     */
    @PostMapping(value = "/list", produces = "application/json;charset=utf-8")
    ApiResult<List<ApplicationComponentDTO>> applicationListWithComponent(@RequestBody @Valid ApplicationQuery applicationQuery);


    /**
     * 查询带权限的组件
     *
     *
     * @param request
     * @param applicationQuery
     * @return
     */
    @PostMapping(value = "/applicationListWithComponentPermissions", produces = "application/json;charset=utf-8")
    ApiResult<List<ApplicationComponentDTO>> applicationListWithComponentPermissions(HttpServletRequest request,
                                                                                     @RequestBody @Valid ApplicationQuery applicationQuery);


    /**
     * 根据关键字（应用名）获取应用数组
     * @param keyword
     * @return
     */
    @GetMapping(value = "/listAppByKeyword", produces = "application/json;charset=utf-8")
    ApiResult<List<ApplicationDTO>> listAppByKeyword(@RequestParam("keyword") String keyword);

    /**
     * 新增应用
     *
     *
     * @param request
     * @param applicationDTO
     * @return
     */
    @PostMapping(value = "", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> addApplication(HttpServletRequest request,
                                      @RequestBody @Valid ApplicationDTO applicationDTO);

    /**
     * 更新应用
     *
     *
     * @param request
     * @param applicationDTO
     * @return
     */
    @PutMapping(value = "", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> updateApplication(HttpServletRequest request,
                                         @RequestBody @Valid ApplicationDTO applicationDTO);

    /**
     * 删除应用
     *
     * @param code
     * @return
     */
    @DeleteMapping(value = "/{code}", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> deleteApplication(@PathVariable("code") String code);

    /**
     * 查询应用
     *
     * @param code
     * @return
     */
    @GetMapping(value = "/{code}", produces = "application/json;charset=utf-8")
    ApiResult<ApplicationComponentDTO> queryApplication(@PathVariable("code") String code);
}
